﻿using System;
using System.Collections.Generic;
using log4net;

namespace SystemX.Utility
{
	public class Logger
	{
		private static readonly object lockHelper=new object();
        private static Dictionary<string, ILog> _Loggers;
        public static Dictionary<string, ILog> Loggers {
            get
            {
                lock (lockHelper) {
                    if (_Loggers == null) {
                        lock (lockHelper) {
                            _Loggers = new Dictionary<string, ILog>();
                        }
                    }
                }
                return _Loggers;
            }
        }

		public static ILog I(string name) {
            var hasLogger = Loggers.ContainsKey(name);
            ILog logger = null;
            if (!hasLogger)
            {
                logger = LogManager.GetLogger(name);
                Loggers[name] = logger;
            }
            else {
                logger = Loggers[name];
            }
            return logger;
		}
        public static ILog I(Type type)
        {
            var name = type.FullName;
            return I(name);
        }
	}
	public class Logger<T>
	{
		public static ILog Current
		{
			get
			{
				return Logger.I(typeof(T));
			}
		}
	}
}
